

import  socket
import  subprocess

ip_port = ('127.0.0.1',9995)

sk = socket.socket()
sk.bind(ip_port)
sk.listen(7)

while True:
    print("server waiting ..... ")
    conn,addr = sk.accept()
    while True:
        client_data = conn.recv(1024)
        if not client_data: break
        print("recv:",client_data)
        cmd = client_data.strip()
        cmd_call = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)

        cmd_result = cmd_call.stdout.read()
        if len(cmd_result) == 0:
            cmd_result =b"cmd execution has no output"
        conn.send(cmd_result)

    conn.close()




